MAKEFLAGS=-j $(if $(CORES),$(CORES),1)

CC=gcc
CFLAGS=-Wall -O3 -DNDBLSCR -DNLGLOG -DNDEBUG -DNCHKSOL -DNLGLPICOSAT -DNLGLDRUPLIG -DNLGLYALSAT

LIBS=-lm
LDEPS=
HDEPS=
AIGER=

all: lingeling



analyze:
	clang --analyze $(CFLAGS) $(shell ls *.c *.h)

liblgl.a: lglib.o lglbnr.o lgldimacs.o makefile
	ar rc $@ lglib.o lglbnr.o lgldimacs.o
	ranlib $@

lingeling: lglmain.o liblgl.a makefile $(LDEPS)
	$(CC) $(CFLAGS) -o $@ lglmain.o -L. -llgl $(LIBS)
iterative: iterative-lglmain.o liblgl.a makefile $(LDEPS)
	$(CC) $(CFLAGS) -o iterative-lingeling iterative-lglmain.o -L. -llgl $(LIBS)
plingeling: plingeling.o liblgl.a makefile $(LDEPS)
	$(CC) $(CFLAGS) -pthread -o $@ plingeling.o -L. -llgl $(LIBS)
treengeling: treengeling.o liblgl.a makefile $(LDEPS)
	$(CC) $(CFLAGS) -pthread -o $@ treengeling.o -L. -llgl $(LIBS)
blimc: blimc.o liblgl.a makefile $(AIGER)/aiger.o $(LDEPS)
	$(CC) $(CFLAGS) -o $@ blimc.o -L. $(AIGER)/aiger.o -llgl $(LIBS)
ilingeling: ilingeling.o liblgl.a makefile $(LDEPS)
	$(CC) $(CFLAGS) -pthread -o $@ ilingeling.o -L. -llgl $(LIBS)
lglmbt: lglmbt.o liblgl.a $(LDEPS)
	$(CC) $(CFLAGS) -o $@ lglmbt.o -L. -llgl $(LIBS)
lgluntrace: lgluntrace.o liblgl.a makefile $(LDEPS)
	$(CC) $(CFLAGS) -o $@ lgluntrace.o -L. -llgl $(LIBS)
lglddtrace: lglddtrace.o liblgl.a makefile $(LDEPS)
	$(CC) $(CFLAGS) -o $@ lglddtrace.o -L. -llgl $(LIBS)

lglmain.o: lglmain.c lglib.h makefile
	$(CC) $(CFLAGS) -c lglmain.c
iterative-lglmain.o: lglmain.c lglib.h makefile
	$(CC) $(CFLAGS) -c iterative-lglmain.c
plingeling.o: plingeling.c lglib.h makefile
	$(CC) $(CFLAGS) -c plingeling.c
treengeling.o: treengeling.c lglib.h makefile
	$(CC) $(CFLAGS) -c treengeling.c
ilingeling.o: ilingeling.c lglib.h makefile
	$(CC) $(CFLAGS) -c ilingeling.c
blimc.o: blimc.c lglib.h $(AIGER)/aiger.h makefile
	$(CC) $(CFLAGS) -I$(AIGER) -c -o $@ blimc.c
lglmbt.o: lglmbt.c lglib.h makefile
	$(CC) $(CFLAGS) -c lglmbt.c
lgluntrace.o: lgluntrace.c lglib.h makefile
	$(CC) $(CFLAGS) -c lgluntrace.c
lglddtrace.o: lglddtrace.c lglib.h makefile
	$(CC) $(CFLAGS) -c lglddtrace.c

lglib.o: lglib.c lglib.h makefile $(HDEPS)
	$(CC) $(CFLAGS) -c lglib.c
lgldimacs.o: lgldimacs.c lgldimacs.h makefile
	$(CC) $(CFLAGS) -c lgldimacs.c
lglbnr.o: lglbnr.c lglcfg.h lglcflags.h makefile
	$(CC) $(CFLAGS) -c lglbnr.c

lglcfg.h: VERSION mkconfig.sh lglbnr.c lglib.c lglmain.c lglcflags.h makefile
	rm -f $@
	./mkconfig.sh > $@
lglcflags.h: makefile
	rm -f $@
	echo '#define LGL_CC "$(shell $(CC) --version|head -1)"' >> $@
	echo '#define LGL_CFLAGS "$(CFLAGS)"' >> $@

clean: clean-all clean-config
clean-config:
	rm -f makefile lglcfg.h lglcflags.h
clean-all:
	rm -f lingeling plingeling ilingeling treengeling blimc
	rm -f lglmbt lgluntrace lglddtrace
	rm -f *.gcno *.gcda cscope.out gmon.out *.gcov *.gch *.plist
	rm -f *.E *.o *.s *.a log/*.log 

.PHONY: all targets clean clean-config clean-all
